import {
  MiddlewareConsumer,
  Module,
  NestModule,
  RequestMethod,
} from '@nestjs/common';
import { UserModule } from './application/user/user.module';
import { CandidateModule } from './application/candidate/candidate.module';
import { SettingModule } from './application/setting/setting.module';
import { VerifyCodeModule } from './application/verify-code/verify-code.module';
import { VoteModule } from './application/vote/vote.module';
import { AppService } from './@nt/services/appService';
import {
  MysqlRemoteConfig,
  RedisAsyncConfig,
} from './application/common/dbConfig';
import { DataMiddleware } from './@nt';

@Module({
  imports: [
    RedisAsyncConfig,
    MysqlRemoteConfig,
    UserModule,
    CandidateModule,
    SettingModule,
    VerifyCodeModule,
    VoteModule,
  ],
  controllers: [],
  providers: [AppService],
})
export class AppModule implements NestModule {
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
  configure(consumer: MiddlewareConsumer) {
    consumer
      .apply(DataMiddleware)
      .forRoutes({ path: '*', method: RequestMethod.ALL });
  }
}
